<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        .layui-table-cell{
            height:50px;
            line-height: 50px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="batchDelete"> 多选删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="functionLogTableId" lay-filter="employeeTableFilter"></table>

    </div>
</div>

<script type="text/html" id="xuhao">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#functionLogTableId',
            url: '/admin/log/queryAllFuncLog',
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [
                [
                {type: "checkbox"},
                {title: '序号',width:70,templet:'#xuhao'},
                {title: '功能操作详情',templet:function (res) {
                        var html = '<img src="'+res.faceImage+'" width="50" height="50" style="border-radius:100%; " />';
                        var funcName = '<span style="color: #00A8FF;">'+res.functionName+'</span>';
                        return html+"员工:"+res.employeeName+"在"+res.actionTime+"    "+funcName;

                    }}
                ]
            ],
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('functionLogTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'batchDelete') {  // 批量删除
                var data = checkStatus.data;

                if (data.length < 1){
                    layer.msg("最少选中一条数据")
                    return false;
                }
                //多选删除
                layer.confirm('确认要删除功能操作日志吗？', {
                    btn : [ '确定', '取消' ]//按钮
                }, function(index) {

                    var arrListId = [];
                    $.each(data,function (index,item) {

                        arrListId.push(item.functionId);

                    })

                    console.log(arrListId.join("-"))

                    $.ajax({
                        url:'/admin/log/batchDeleteFuncLog',
                        type:'post',
                        data:{
                            funcIds:arrListId.join("-")
                        },
                        dataType:'json',
                        success:function (res) {

                            layer.msg(res.message+",正在刷新表格中",function () {
                                //刷新表格
                                table.reload('functionLogTableId', {
                                    url: '/admin/log/queryAllFuncLog'

                                });
                            })

                        }
                    })


                    layer.close(index);

                });

            }
        });

        //监听表格复选框选择
        table.on('checkbox(employeeTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(employeeTableFilter)', function (obj) {
            var data = obj.data;

            console.log(data)

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>
